﻿using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Domain.PM;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using FarmSmartSleep.Organ.API.Application.Commands.CottagesCommands;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.ProductionManagement.FemaleRen
{
    public class FemaleRenDetailHandler : IRequestHandler<FemaleRenDetailCommand, ResultT<EwePregnancyCheckRecord>>
    {
        private readonly ILogger<FemaleRenDetailHandler> logger;
        private readonly IBaseRepository<EwePregnancyCheckRecord> ewePregnancyCheckRecordRepository;

        public FemaleRenDetailHandler(IBaseRepository<EwePregnancyCheckRecord> ewePregnancyCheckRecordRepository, ILogger<FemaleRenDetailHandler> logger)
        {
            this.ewePregnancyCheckRecordRepository = ewePregnancyCheckRecordRepository;
            this.logger = logger;
        }

        /// <summary>
        /// 反填母羊妊检信息方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ResultT<EwePregnancyCheckRecord>> Handle(FemaleRenDetailCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new ResultT<EwePregnancyCheckRecord>();
                result.Item = ewePregnancyCheckRecordRepository.GetAll().FirstOrDefault(x => x.EwePregnancyCheckRecordId == request.EwePregnancyCheckRecordId);
                logger.LogInformation("反填母羊妊检信息方法调用成功");
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("反填母羊妊检信息方法调用失败" + ex);
                throw;
            }
        }
    }
}
